package zl.osimall.manager.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zl.osimall.common.bean.RespBean;
import zl.osimall.common.bean.User;
import zl.osimall.common.exception.SteduException;
import zl.osimall.common.service.UserService;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/page")
    public RespBean selectConditionByPage(User condition,
                                          Integer pageNum, Integer pageSize) {
        PageInfo<User> pageInfo = userService.selectByLike(condition, pageNum, pageSize);
        return RespBean.ok("查询成功", pageInfo);
    }

    @GetMapping("/{id}")
    public RespBean selectById(@PathVariable("id") Integer id) throws SteduException {
        return RespBean.ok("查询成功", userService.selectById(id));
    }


    @PutMapping
    public RespBean update(@RequestBody User user) throws SteduException {
        userService.update(user,null);
        return RespBean.ok("修改成功");
    }
}
